#ifndef VM_PAGE_H
#define VM_PAGE_H

#include <debug.h>
#include <hash.h>

/* Supplemental page table entry. */
struct page
{
	struct hash_elem hash_elem;		/* Hash table element. */
	void *uaddr;									/* User virtual address. A hash key. */
	int swap_dsk_idx;							/* Index of a swap disk sector. -1 if not swapped. */
	struct thread *owner;					/* A thread that owns this page. */
};

bool pagetbl_init (struct thread *t);
void pagetbl_destroy (struct thread *t);
bool page_insert (void *upage, void *kpage, bool writable);
struct page *page_lookup (void *address, struct thread *t);
void *get_kpage (struct page *p);
unsigned page_hash (const struct hash_elem *p_, void *aux UNUSED);
bool page_less (const struct hash_elem *a_, const struct hash_elem *b_, void *aux UNUSED);
void page_destroy (struct hash_elem *p_, void *aux UNUSED);

bool page_stack_growth(void *uaddr);
#endif /* vm/page.h */
